#include <iostream>
#include "HashMap.h"

void Sort(std::string& s,int start,int end)
{   
    if(start> end)
        return;
    int right = end;
    int left = start;
    char temp = s[left];
    while(left < right)
    {
        // int mid = (left&right)+(left^right)>>1;
        while(left < right&&temp < s[right])
            right--;
        if(left  < right)
            s[left++] = s[right];
        while(left < right&& temp  > s[left])
            left++;
        if(left < right)
             s[right--] = s[left];
    }
    s[left] = temp;
    Sort(s,start,left-1);
    Sort(s,right+1,end);
}

int main()
{   


     HashMap m(100);
    // std::string strs[] = {+"zhang","wang","li","zhang","li","zhang"};

    // for(int i = 0; i < sizeof(strs)/sizeof(std::string);i++)
    // {
    //     m[strs[i]]++;
    // }
    // m.Insert("zhangsan",1);
    // m.Insert("lisi",2);
    // m.Insert("wangwu",6);

    // int *p = m.Get("wangwu");
    // if(p)
    //     std::cout<<*p<<std::endl;
    // m.show();
    // m["zhangsan"] = 5;
    // m["lisi"] = 6;
    // m["wangwu"] = 7;

    // m["zhangsan"] = 8;

    std::string strs[] = {"eat", "tea", "tan", "ate", "nat", "bat"};

    for(int i = 0;i <sizeof(strs)/sizeof(std::string); i++)
    {   
        std::string temp = strs[i];
        Sort(temp,0,temp.size()-1);
        // std::cout<<"temp : "<<temp<<std::endl;
        m.Insert(temp,strs[i]);
    }
    m.showBykey();
    return 0;
}